package nc.ui.levmmeampoundbill.poundbill.view;

import java.awt.BorderLayout;
import java.awt.Font;
import java.awt.Rectangle;
import javax.swing.Action;
import javax.swing.BorderFactory;
import javax.swing.JTextField;
import nc.ui.levmmeampoundbill.poundbill.model.PoundSettingBillManageModel;
import nc.ui.levmmeampoundbill.poundbill.util.PoundAreaColor;
import nc.ui.pub.beans.UIPanel;
import nc.ui.pub.beans.UITextField;
import nc.ui.pub.beans.ValueChangedListener;
import nc.ui.queryarea.util.QueryAreaColor;
import nc.vo.levmew.ewdoc.AggEwDocVO;
import nc.vo.levmew.ewdoc.EwDocHeadVO;
import nc.vo.mmgp.util.MMBooleanUtil;
import nc.vo.pub.lang.UFDouble;

public class SerialDataPanel extends UIPanel {
	public static final int DEFAULT_HEIGHT = 110;
	private ValueChangedListener valueChangedListener;
	private JTextField mtfData;
	public UITextField serialPortFiled = null;

	private boolean bSimulateRunStatus = false;

	private SerialPortTitlePanel titlePanel;

	private PoundSettingBillManageModel settingModel;

	public void initUI() {
		initialize();
	}

	private void initialize() {
		setLayout(new BorderLayout());
		setBorder(BorderFactory.createLineBorder(QueryAreaColor.BORDER_COLOR));

		add(getTitlePanel(), "North");
		add(getMtfData(), "Center");
	}

	private SerialPortTitlePanel getTitlePanel() {
		return titlePanel;
	}

	public boolean infraredStatusOk() {
		AggEwDocVO currEWVO = getSettingModel().getCurrEWVO();

		if (!MMBooleanUtil.booleanValue(currEWVO.getParentVO().getEnableinf())) {
			return true;
		}
		return getTitlePanel().infraredStatusOk();
	}

	public void setMiniAction(Action miniAction) {
		getTitlePanel().addAction2RightToolbar(miniAction);
	}

	public ValueChangedListener getValueChangedListener() {
		return valueChangedListener;
	}

	public void setValueChangedListener(ValueChangedListener valueChangedListener) {
		this.valueChangedListener = valueChangedListener;
	}

	public UFDouble getCurrentWeight() {
		String weight = getMtfData().getText();
		if ((weight != null) && (!weight.equals(""))) {
			return new UFDouble(weight);
		}
		return new UFDouble(0);
	}

	public JTextField getMtfData() {
		if (this.mtfData == null) {
			this.mtfData = new JTextField();
			this.mtfData.setBounds(new Rectangle(6, 32, 230, 63));
			this.mtfData.setText("0.00");

			this.mtfData.setForeground(PoundAreaColor.SERIAL_FONT_COLOR);
			this.mtfData.setEditable(false);
			this.mtfData.setBackground(PoundAreaColor.SERIAL_PANEL_COLOR);
			this.mtfData.setHorizontalAlignment(4);
			this.mtfData.setFont(new Font("Microsoft YaHei UI", 1, 50));
		}

		return mtfData;
	}

	public boolean isbSimulateRunStatus() {
		return bSimulateRunStatus;
	}

	public void setbSimulateRunStatus(boolean bSimulateRunStatus) {
		this.bSimulateRunStatus = bSimulateRunStatus;
	}

	public void reFlashPonder() {
	}

	public PoundSettingBillManageModel getSettingModel() {
		return settingModel;
	}

	public void setSettingModel(PoundSettingBillManageModel settingModel) {
		this.settingModel = settingModel;
	}

	public void setTitlePanel(SerialPortTitlePanel titlePanel) {
		this.titlePanel = titlePanel;
	}

	public int getDefaultHeight() {
		return 110;
	}
}